﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Objects;
using BAL;
using System.Collections.Generic;

public partial class Admin_UCControls_UCKhachHang_Duyet : System.Web.UI.UserControl
{
    public static string srtPath;
    public static DanhSachKhachHang ItemKhachHang;
    public DangKy ItemDangKy;
    public static List<DanhSachTheMua> ListDanhSachTheMua;
    public static List<ThongTinDuyet> ListDuyet;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ItemKhachHang = new DanhSachKhachHang();
            ItemKhachHang = (DanhSachKhachHang)Session["ItemKhachHang"]; 

            if (ItemKhachHang != null)
            {
                GetThongTinDangKy(ItemKhachHang.Id);

                lblNgayDangKy.Text = ItemKhachHang.NgayDangKy.ToString().Substring(0, 10);
                lblNgayNhanThe.Text = ItemKhachHang.NgayNhanThe.ToString().Substring(0, 10);
                lblHetHan.Text = ItemKhachHang.NgayHetHan.ToString().Substring(0, 10);

                GetDuyet(ItemKhachHang.Id, Convert.ToDateTime(ItemKhachHang.NgayDangKy));
                GetDanhSachTheMua(Convert.ToDateTime(ItemKhachHang.NgayDangKy), ItemKhachHang.Id);
            }

            
        }
    }

    private void GetDuyet( int idKhachHang,DateTime ngayDangKy)
    {
        ListDuyet = BALThongTinDuyet.GetAllItem(idKhachHang,ngayDangKy);

        if (ListDuyet.Count > 0)
        {
            GridThongTinDuyet.DataSource = ListDuyet;

        }
        GridThongTinDuyet.PageIndex = 0;
        GridThongTinDuyet.DataBind();
    }

    private void GetThongTinDangKy(int idKhachHang)
    {
      
        if (ItemDangKy != null)
        {

            lblNgayDangKy.Text = ItemKhachHang.NgayDangKy.ToString();
            lblNgayNhanThe.Text = ItemKhachHang.NgayNhanThe.ToString();
            lblHetHan.Text = ItemKhachHang.NgayHetHan.ToString();

           
            if (ItemDangKy.IdPhuongThucThanhToan > 0)
            {
                PhuongThucThanhToan itemPhuongThucThanhToan = new PhuongThucThanhToan();
                itemPhuongThucThanhToan = BALPhuongThucThanhToan.GetById(ItemDangKy.IdPhuongThucThanhToan);
                lblPTTT.Text = itemPhuongThucThanhToan.HinhThuc.ToString();
            }
        }
    }

    public string PathImage()
    {
        return srtPath = "~/images/Generic Card/MauThe/";
    }

    private void GetDanhSachTheMua(DateTime ngayDangKy,int idKhachHang)
    {
        ListDanhSachTheMua = BALDanhSachTheMua.GetAllItem(ngayDangKy, idKhachHang);

        if (ListDanhSachTheMua.Count > 0)
        {
            GridThongTinThe.DataSource = ListDanhSachTheMua;

        }
        GridThongTinThe.PageIndex = 0;
        GridThongTinThe.DataBind();

    }

    public string TrangThaiDuyet(Object trangthai)
    {

        string returnValue = string.Empty;
        if (!string.IsNullOrEmpty(trangthai.ToString()))
        {
            if (trangthai.ToString() == "0")
            {
                returnValue = "Chờ duyệt";
            }
            else if (trangthai.ToString() == "1")
            {
                returnValue = "Đã duyệt";
            }
            else { returnValue = "Không duyệt"; }
        }
        return returnValue;
    }

    //protected void GridThongTinThe_PageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    GridThongTinThe.DataSource = ListDanhSachTheMua;
    //    GridThongTinThe.PageIndex = e.NewPageIndex;
    //    GridThongTinThe.DataBind();
    //}
}
